<!--
  车位表添加页面
  User: YanZengBao
  Date: 2020-02-19
-->
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<!-- BEGIN FORM-->
<div class="portlet light">
    <div class="portlet-title">
        <div class="caption">
            <span class="caption-subject font-red-sunglo bold uppercase">车位添加</span>
            <span class="caption-helper">添加一条车位数据</span>
        </div>
    </div>
    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="save-module">
            <div class="form-body">

                <!--  字段信息-->
                <!-- 停车场ID 字段信息-->
                <div class="form-group hide">
                    <label class="col-md-3 control-label">停车场名称</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" id="parkName" required name="parkName"
                                       placeholder="停车场名称">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 停车场名称 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场名称</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select class="form-control" id="parkId" required name="parkId" onclick="choosePark()">
                                    <option value="">请选择停车场</option>
                                    <option th:each="data,iterStat : ${parkList}" th:value="${data.id}"
                                            th:text="${data.name}"></option>
                                </select>
                                <!-- <input type="text" class="form-control" required name="parkName" placeholder="停车场名称">-->
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 车位编号 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">车位编号</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="32" required name="parkinglotCode"
                                       placeholder="车位编号">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 车位类型（1，有地锁车位  2,有地磁 3.无地锁车位） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">车位类型</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select class="form-control" required name="parkinglotType">
                                    <option value="3">普通车位</option>
                                    <option value="1">地锁车位</option>
                                    <option value="2">地磁车位</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 区域 字段信息-->
                <div class="form-group ">
                    <label class="col-md-3 control-label">车场区域（非必选）</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select id="area" class="form-control" name="areaId"></select>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 备注 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">备注信息</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="255" name="intro" placeholder="备注信息">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 地锁的唯一标识(控制地锁) 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">地锁标识</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="50" name="lockNumber"
                                       placeholder="地锁的唯一标识(无地锁可不填)">
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-7">
                                <button type="button" class="btn green" onclick="save();">保存</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_addModule);">取消
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>

<script>

    $(function () {
        //初始化页面
        initPage();
    });

    //选择停车场，保存停车场名称
    function choosePark() {
        let parkName = $("#parkId option:selected").text();
        $("#parkName").val(parkName);

        $("#area").empty();
        var options = $("#parkId option:selected");
        if (options.text().trim() != "请选择停车场" && "" != options.text().trim()) {
            tools.post("/parkArea/findAreaByparkId", {"parkId": options.val()}, function (data) {
                $("#area").append('<option value="">请选择区域</option>');
                for (let cs in data.data) {
                    $("#area").append("<option value=\"" + data.data[cs].id + "\">" + data.data[cs].name + "</option>");
                }
                ;
            });
        }
    }


    function save() {
        let param = tools.formParams("save-module");
        if (tools.valid("save-module")) {
            tools.post("/parkinglot/save", param, function (data) {
                if (data.success) {
                    layer.msg(data.message, {icon: 1, time: 2000}, function () {
                        //刷新列表页面
                        toPage(null);
                        //关闭弹窗
                        layer.close(layer_addModule);
                    });
                } else {
                    tools.errorTip(data);
                }
            });
        }
    }

</script>
</html>